import React,{Component} from  'react'
import { Table,Pagination  } from 'antd';
import {connect} from 'react-redux'
import {userList} from "../../redux/user.redux";

import './user.less'
import {getCount} from "../../redux/home.redux";
import {getStore} from "../../tool";

const columns = [{
    title: 'ID',
    dataIndex: 'id',
    render: text => <a href="javascript:;">{text}</a>,
}, {
    title: '用户名',
    dataIndex: 'username',
}, {
    title: '邮箱',
    dataIndex: 'email',
},
    {
        title: '电话',
        dataIndex: 'phone',
    },
    {
        title: '注册时间',
        dataIndex: 'createTime',
    }];
class User extends Component{
    constructor(props){
        super(props);
    }
    onChangePage(pageNumber) {
        this.props.userList(pageNumber);
    }

    componentDidMount() {
        this.props.userList(1);
    }
    render(){
        return (
            <div className='user'>
                <h1 className='page-header'>用户管理</h1>
                <Table size='small'
                       pagination={false}
                       columns={columns}
                       dataSource={this.props.user.list.list}
                       bordered
                />
                <div className="pagination">
                    { this.props.user.list.total?<Pagination style={{textAlign:'center'}} showQuickJumper onChange={this.onChangePage.bind(this)} pageSize={10} defaultCurrent={this.props.user.list.current} total={this.props.user.list.total} />:null}
                </div>
            </div>
        )
    }
}


function mapStateToProps(state){
    return state;
}

const mapDispatchToProps = (dispatch) => ( { // <- forgot the wrapping with ( here
    userList: (pageNum) => {
        dispatch(userList(pageNum))
    }
} )
export default connect(mapStateToProps, mapDispatchToProps)(User);

